; (function (win, doc) {


    // 传入的参数接口
    interface DefaultOption {
        direction: string,
        color: number,
        opacity: number,
        width: number,
        height: number,
    }


    // 默认参数配置
    const defaultSettings: DefaultOption = {
        direction: 'right',
        color: 0x5ecfe2,
        opacity: 0.9,
        width: 200,
        height: 120
    };

    interface CamPosition {
        x: number, y: number, z: number
    }



    class PaintCameraCilent {
        chaunveMap: any;

        constructor(camNodeId: string, floorid: string, GIM: any, map: any, options: DefaultOption) {

            let self: any = this;

            if (!camNodeId && !floorid && !GIM && !map) {
                throw new Error("please afferent parmas");
            }

            if (GIM.Points[camNodeId].Code != "camera") {
                throw 'please afferent camera nodeId'
            }

            self = Object.assign(self, defaultSettings, options);
            self.chaunveMap = map;

            const camPosition:CamPosition = {
                x: GIM.Points[camNodeId].x,
                y: GIM.Points[camNodeId].y,
                z: 80
            }

            let coords = [];


            if (self.direction == 'left') {

                coords = [{
                    x: camPosition.x - 40,
                    y: camPosition.y - (self.height / 2),
                    z: 5
                }, {
                    x: camPosition.x - 40,
                    y: camPosition.y + (self.height / 2),
                    z: 5
                }, {
                    x: camPosition.x - (40 + self.width),
                    y: camPosition.y + (self.height / 2),
                    z: 5
                }, {
                    x: camPosition.x - (40 + self.width),
                    y: camPosition.y - (self.height / 2),
                    z: 5
                }];


            } else if (self.direction == 'right') {

                coords = [{
                    x: camPosition.x + 40,
                    y: camPosition.y - (self.height / 2),
                    z: 5
                }, {
                    x: camPosition.x + 40,
                    y: camPosition.y + (self.height / 2),
                    z: 5
                }, {
                    x: camPosition.x + (40 + self.width),
                    y: camPosition.y + (self.height / 2),
                    z: 5
                }, {
                    x: camPosition.x + (40 + self.width),
                    y: camPosition.y - (self.height / 2),
                    z: 5
                }];



            } else if (self.direction == 'front') {

                coords = [{
                    x: camPosition.x - (self.height / 2),
                    y: camPosition.y - (40 + self.width),
                    z: 5
                }, {
                    x: camPosition.x + (self.height / 2),
                    y: camPosition.y - (40 + self.width),
                    z: 5
                }, {
                    x: camPosition.x + (self.height / 2),
                    y: camPosition.y - 40,
                    z: 5
                }, {
                    x: camPosition.x - (self.height / 2),
                    y: camPosition.y - 40,
                    z: 5
                }
                ];


            } else if (self.direction == 'behind') {

                coords = [{
                    x: camPosition.x - (self.height / 2),
                    y: camPosition.y + (40 + self.width),
                    z: 5
                }, {
                    x: camPosition.x + (self.height / 2),
                    y: camPosition.y + (40 + self.width),
                    z: 5
                }, {
                    x: camPosition.x + (self.height / 2),
                    y: camPosition.y + 40,
                    z: 5
                }, {
                    x: camPosition.x - (self.height / 2),
                    y: camPosition.y + 40,
                    z: 5
                }
                ];

            }

            self.clientCamare = this.genRecCilent(map, coords, floorid, self.color, self.opacity,camPosition)

            return self;

        }

        /**
         * 私有方法 生产可视域
         */
        private genRecCilent(map: any, coords: any, floorid: string, color: number, opacity: number,camPosition:CamPosition) {

            let clientCamare = []


            // 增加块标注
            clientCamare[coords.length] = map.addPolygonMarker(coords, floorid, color, opacity);

            // 添加线标注，一共四条线  一共传入三个参数 第一个坐标点数组  第二个指定楼层  第三个线条颜色
            coords.forEach((e:any, index: number) => {

                clientCamare[index] = map.addPathMarker([camPosition,{
                    x: e.x,
                    y: e.y,
                    z: 3
                }], floorid, color);

            })

            return clientCamare;

        }

        /**
         * 清除可视域 传入生产可视域的标识数组
         */
        public cleanCilent(clientCamare:[number]) {

            clientCamare.forEach(e => {
                this.chaunveMap.removeMarker(e);
            })
            
        }

    }


    (<any>window).PaintCameraCilent = PaintCameraCilent;

})(window, document)